# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : small01.py
# @Time     : 2024/3/12 1:08
# @Author   : Robot-Zsj
"""
description:

输入
3 3
0 0 0
0 1 0
0 0 0

输出
5

输入
3 3
1 0 0
0 1 0
0 0 0

输出
6
"""


def main():
    rows, cols = map(int, input().split())
    grid = [[0] * (cols + 2) for _ in range(rows + 2)]
    dirs = [(0, -1), (-1, 0), (0, 1), (1, 0), (0, 0)]
    for i in range(1, rows + 1):
        row = list(map(int, input().split()))
        for j in range(1, cols + 1):
            grid[i][j] = row[j - 1]
    ret = 0
    for i in range(1, rows + 1):
        for j in range(1, cols + 1):
            for dx, dy in dirs:
                x = i + dx
                y = j + dy
                if 1 <= x <= rows and 1 <= y <= cols and grid[x][y] == 1:
                    ret += 1
                    break
    print(ret)


while True:
    try:
        main()
    except:
        break
